package com.sinaapp.zhangziyou.utils;

import java.util.Properties;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

public class EmailUtil {
	
	public static void sendEmailTo(String email,String code) {
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();  
	    // 设定mail server  
	    mailSender.setHost("smtp.qq.com");  

	    // 建立邮件消息  
	    SimpleMailMessage mailMessage = new SimpleMailMessage();  
	    // 设置收件人，寄件人 用数组发送多个邮件  
	    // String[] array = new String[] {"sun111@163.com","sun222@sohu.com"};  
	    // mailMessage.setTo(array);  
	    mailMessage.setTo(email);  
	    mailMessage.setFrom("958864493@qq.com");  
	    mailMessage.setSubject("密码重置");  
	    mailMessage.setText("密码重置地址：http://localhost:8080/URACS/verifyCode?code="+code);  

	    mailSender.setUsername("958864493"); // 根据自己的情况,设置username  
	    mailSender.setPassword("yjhmdf"); // 根据自己的情况, 设置password  

	    Properties prop = new Properties();  
	    prop.put("mail.smtp.auth", "true"); // 将这个参数设为true，让服务器进行认证,认证用户名和密码是否正确  
	    prop.put("mail.smtp.timeout", "25000");  
	    mailSender.setJavaMailProperties(prop);  
	    // 发送邮件  
	    mailSender.send(mailMessage);
	}
	
	public static void main(String[] args) {
		sendEmailTo("707582070@qq.com","12334556");
	}
	
}